package cn.nange.cmfz.service.impl;

import cn.nange.cmfz.dao.AdminDao;
import cn.nange.cmfz.entity.Admin;
import cn.nange.cmfz.service.AdminService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDao adminDao;

    @Override
    public void register(Admin a) {
        adminDao.insert(a);
    }

    @Override
    public void update(Admin a) {
        adminDao.update(a);
    }

    @Override
    public void ban(Integer id) {
        adminDao.ban(id);
    }

    @Override
    public void delete(Integer id) {
        adminDao.delete(id);
    }

    @Override
    public Admin showOne(Integer id) {
        return adminDao.selectOne(id);
    }

    @Override
    public Admin login(String name) {
        return adminDao.selectByName(name);
    }

    @Override
    public PageInfo<Admin> showAll(int page, int rows) {
        PageHelper.startPage(page, rows);
        PageInfo<Admin> pageInfo = new PageInfo<>(adminDao.selectAll());
        return pageInfo;
    }
}
